package com.tianfeng.huayi.controller;

import com.tianfeng.huayi.entity.ParkSpaceVehicle;
import com.tianfeng.huayi.entity.ParkingSpace;
import com.tianfeng.huayi.entity.Property;
import com.tianfeng.huayi.entity.Vehicle;
import com.tianfeng.huayi.service.IParkingSpaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/parkingSpace")
public class ParkingSpaceController {

    @Autowired
    private IParkingSpaceService parkingSpaceService;

    /**
     * 查询车辆车位信息列表
     */
    @PostMapping("/list")
    @ResponseBody
    public ResponseEntity<Map<Object, Object>> list(@RequestBody Vehicle vehicle1)
    {
        Map<Object,Object> response = new HashMap<>();
        List<ParkSpaceVehicle> spaceVehicleList = new ArrayList<>();
        // 根据业主ID查询出业主的所有车辆信息
        List<Vehicle> vehicleList = parkingSpaceService.selectVehicleList(vehicle1);
        if (vehicleList != null && !vehicleList.isEmpty()) {
            for (Vehicle vehicle : vehicleList) {
                ParkingSpace parkingSpace = parkingSpaceService.selectParkingSpaceBySpaceId(vehicle.getSpaceId());
                ParkSpaceVehicle spaceVehicle = new ParkSpaceVehicle();
                spaceVehicle.setVehicle(vehicle);
                spaceVehicle.setParkingSpace(parkingSpace);
                spaceVehicleList.add(spaceVehicle);
            }
            response.put("code", 200);
            response.put("msg", "查询成功");
            response.put("data", spaceVehicleList);
        } else {
            response.put("code", 400);
            response.put("msg", "未找到匹配的车辆信息");
        }
        return ResponseEntity.ok(response);
    }


}
